﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

/// <summary>
/// Summary description for GetDanhMuc
/// </summary>
public class DanhMucDA
{
    Connection conn = new Connection();
    
    public List<DanhMuc> GetData()
    {
        try
        {
            List<DanhMuc> lstDanhMuc = new List<DanhMuc>();
            conn.openCon();
            string sql = " SELECT * FROM NhanHieu where ID in(select nhanHieuID from sanpham WHERE (Xoa = 0) group by NhanHieuID) and NhanHieu.ten !='Other' and Xoa=0";
            SqlCommand cmd = new SqlCommand(sql, conn.getCon());
            SqlDataReader reader = cmd.ExecuteReader();
            DanhMuc d = null;
            while (reader.Read())
            {
                d = new DanhMuc(reader.GetInt32(0), reader.GetString(1), reader.GetBoolean(3));
                lstDanhMuc.Add(d);
            }
            reader.Close();
            conn.closeCon();
            return lstDanhMuc;
        }
        catch (Exception)
        {

            throw;
        }
        finally {
            conn.closeCon();
        }
    }

    public List<DanhMuc> GetOther()
    {
        try
        {
            List<DanhMuc> lstDanhMuc = new List<DanhMuc>();
            conn.openCon();
            string sql = " SELECT * FROM NhanHieu where ID in(select nhanHieuID from sanpham WHERE (Xoa = 0) group by NhanHieuID) and nhanhieu.ten='Other' and Xoa=0";
            SqlCommand cmd = new SqlCommand(sql, conn.getCon());
            SqlDataReader reader = cmd.ExecuteReader();
            DanhMuc d = null;
            while (reader.Read())
            {
                d = new DanhMuc(reader.GetInt32(0), reader.GetString(1), reader.GetBoolean(3));
                lstDanhMuc.Add(d);
            }
            reader.Close();
            conn.closeCon();
            return lstDanhMuc;
        }
        catch (Exception)
        {

            throw;
        }
        finally {
            conn.closeCon();
        }
    }
}